<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Block_Admin_Tag_Grid extends Block_Admin_Grid {

	public function __construct() {
		$this->setTitle('Manage Tag');
		App::objectSingleton('Core_Cookie')->init('admin', 'tag');
	}
	
	protected function _prepareCollection() {
		$collection = App::object('Entity_Tag')->getCollection()->addPostCount();
		$select = $collection->getSelect();

		if (App::get('name'))
			$select->where("name LIKE '".App::get('name')."'");
		if (App::get('post_count'))
			$select->having("post_count = ".App::get('post_count'));
		return $collection;
	}
	
	protected function getSortableColumns() {
		return array('name', 'post_count');
	}
}